package cc.admin.common.db.table.entity;

/**
 * 数据类型
 */
public enum DbColumnType {

	VARCHAR,TEXT,DATE,DATETIME,TIME,TIMESTAMP,INT,LONG,DOUBLE,NUMBER,FLOAT,BLOB;

	public static DbColumnType convert(String columnType) {
		columnType = columnType.toUpperCase();
		if (columnType.indexOf("(") > 1) {
			columnType = columnType.substring(0, columnType.indexOf("("));
		}
		switch (columnType) {
			case "CHAR":
			case "VARCHAR":
			case "VARCHAR2":
			case "NCHAR":
			case "NVARCHAR":
			case "NVARCHAR2":
			case "UNIQUEIDENTIFIER":
			case "VARBINARY":
				return VARCHAR;
			case "CLOB":
			case "NCLOB":
			case "TEXT":
			case "MEDIUMTEXT":
			case "LONGTEXT":
			case "NTEXT":
				return TEXT;
			case "SMALLINT":
			case "TINYINT":
			case "INT":
			case "BIT":
				return INT;
			case "BIGINT":
				return INT;
			case "LONG":
				return LONG;
			case "FLOAT":
				return FLOAT;
			case "DOUBLE":
			case "DECIMAL":
				return DOUBLE;
			case "NUMERIC":
			case "NUMBER":
				return NUMBER;
			case "DATE":
				return DATE;
			case "DATETIME":
				return DATETIME;
			case "TIME":
				return TIME;
			case "TIMESTAMP":
				return TIMESTAMP;
			case "BLOB":
			case "LONGBLOB":
			case "IMAGE":
				return BLOB;
			default:
				throw new RuntimeException("不支持的数据类型" + columnType);
		}
	}
}
